package com.mjf.spark.day06

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

import scala.util.parsing.json.JSON

/**
 * 读取Json格式数据
 */
object Spark03_ReadJson {
  def main(args: Array[String]): Unit = {

    // 创建SparkConf配置文件
    val conf = new SparkConf().setMaster("local[*]").setAppName("Spark03_ReadJson")
    // 创建SparkContext对象
    val sc = new SparkContext(conf)

    // {"name": "lucy","age": 18}
    // {"name": "jack","age": 28}
    val rdd: RDD[String] = sc.textFile("D:\\code\\spark\\input\\test.json")

    val resRDD: RDD[Option[Any]] = rdd.map(JSON.parseFull)

    resRDD.collect().foreach(println)

    // 关闭连接
    sc. stop()

  }
}
